<?php
class PublicAction extends Action {
    function _initialize() {
        import('@.ORG.Session');
        $sid = Session::get(C('USER_AUTH_KEY'));
    }
    public function login() {
        
        $this->display("Public:login");
    }
    public function dologin() {

            $Admin = D("Admin");
            $map['email'] = $_POST['email'];
            $map['password'] = md5($_POST['password']);
            $checkAdmin = $Admin->where($map)->find();
            if(!$checkAdmin) {
                $this->assign("jumpUrl","__APP__");
                $this->error("邮件地址或密码不正确！");
            }else {
                Session::set(C('USER_AUTH_KEY'),$checkAdmin['id']);
                Session::set('admin',$checkAdmin['email']);
                Session::set('lastlogintime',$checkAdmin['lastlogintime']);
                $Admin->where("id = ".$checkAdmin['id'])->setField("lastlogintime",time());
                $this->assign("jumpUrl","__APP__/Index");
                $this->success("登陆成功！");
            }
        
    }
    public function verify() {
        $type = isset($_GET['type'])?$_GET['type']:'gif';
        import("ORG.Util.Image");
        Image::buildImageVerify(4,1,$type,'','20px');
    }
    public function logout() {
        if(Session::is_set(C('USER_AUTH_KEY'))) {
            Session::clear();
            $this->assign('jumpUrl',__URL__.'/login');
            $this->success("注销成功！");
        }else {
            $this->assign('jumpUrl',__URL__.'/login');
            $this->error('已经注销！');
        }
        $this->forward();
    }
}
?>
